package me.zhengjie.modules.pay.service;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.service.payments.jsapi.JsapiService;
import com.wechat.pay.java.service.refund.RefundService;
import me.zhengjie.exception.BizException;
import me.zhengjie.modules.pay.domain.req.BuyProductReq;
import me.zhengjie.modules.pay.domain.req.OpenVipReq;
import me.zhengjie.modules.biz.domain.resp.WxPayResp;
import me.zhengjie.modules.pay.domain.req.RefundReq;
import me.zhengjie.modules.pay.domain.req.WxPayReq;

import static me.zhengjie.modules.pay.domain.constant.WXPayConstants.*;
import static me.zhengjie.modules.pay.domain.constant.WXPayConstants.API_V3KEY;

public interface WxPayService {

    WxPayResp openVip(OpenVipReq openVipReq) throws Exception;

    void queryOrder(WxPayReq wxPayReq) throws BizException;

    Boolean closeOrder(WxPayReq wxPayReq) throws BizException;

    void wxPayNotify(String notifyXml) throws JsonProcessingException;

    Boolean refundOrder(RefundReq req) throws BizException;

    void refundNotify(String notifyXml) throws JsonProcessingException;

    WxPayResp buy(String orderSn) throws Exception;



    static JsapiService createJsapiService() {
        Config config =
                new RSAAutoCertificateConfig.Builder()
                        .merchantId(MCH_ID)
                        .privateKey(PRIVATE_KEY)
                        .merchantSerialNumber(MCH_SERIAL_NO)
                        .apiV3Key(API_V3KEY)
                        .build();

        return new JsapiService.Builder().config(config).build();
    }

    static RefundService createRefundJsapiService() {
        // 初始化申请退款的配置
        Config config =
                new RSAAutoCertificateConfig.Builder()
                        .merchantId(MCH_ID)
                        .privateKey(PRIVATE_KEY)
                        .merchantSerialNumber(MCH_SERIAL_NO)
                        .apiV3Key(API_V3KEY)
                        .build();

        return new RefundService.Builder().config(config).build();
    }

}
